<?php
require_once('../../../config.php');
require_once($CFG->libdir . '/accesslib.php');
require_once($CFG->libdir . '/adminlib.php');

//yeu cau login,sau khi login tu dong chuyen sang trang chu
global $USER;
if ($USER->id == null){
    $SESSION->homepage = true;
    require_login($SITE);
}
if($SESSION->homepage){
    $SESSION->homepage = null;
    redirect( $CFG->wwwroot);
}

//class
require_once($CFG->dirroot . '/local/blackboxsurvey/class/survey.php');
require_once($CFG->dirroot . '/local/blackboxsurvey/class/questions.php');

define('AJAX_SCRIPT', true);

//lay survey id can xoa
$id = required_param('id', PARAM_TEXT);

/* Xoa question */
$temp = new b_survey();
$success = $temp->delete_survey($id);
//update question status
$u_question = new b_questions();
$rs = $temp->get_survey_question_bySurveyID($id);

foreach($rs as $r){
	$q['id'] = $r->ques_id;
	$q['status'] = $r->status - 1;
	$u_question->update_question($q);
}
$temp->delete_survey_question_bySurveyID($id);
//kiem tra xoa thanh cong
if($success){
	echo "true";
}
else{
    echo "false";
}